package definite.Guide.Book.JFileChooser;

import java.awt.Color;
import java.io.File;

import javax.swing.Icon;
import javax.swing.filechooser.FileView;

import definite.Guide.Book.ToggleButton.DiamondIcon;

public class JavaFileView extends FileView {
	// field
	private Icon javaIcon = new DiamondIcon(Color.BLUE);
	private Icon classIcon = new DiamondIcon(Color.GREEN);
	private Icon htmlIcon = new DiamondIcon(Color.RED);
	private Icon jarIcon = new DiamondIcon(Color.PINK);

	// get name of file
	@Override
	public String getName(File file) {
		String fName = file.getName();
		if (fName.endsWith(".java")) {
			String name = fName + " : " + fName.length();
			return name;
		}
		return null;
	}

	// get description about the type of a giving file
	@Override
	public String getTypeDescription(File f) {
		String fName = f.getName();
		String des = null;

		if (fName.endsWith(".java"))
			des = "Java Source File";
		if (fName.endsWith(".class"))
			des = "Java Class File";
		if (fName.endsWith(".jar"))
			des = "Java Achieve File";
		if (fName.endsWith(".html") || fName.endsWith(".htm"))
			des = "Applet Loader";
		return des;
	}

	// get Icon of File
	@Override
	public Icon getIcon(File f) {
		if (f.isDirectory())
			return null;
		else {
			Icon icon = null;
			String name = f.getName();
			if (name.endsWith(".java"))
				icon = javaIcon;
			else if (name.endsWith(".class"))
				icon = classIcon;
			else if (name.endsWith(".jar"))
				icon = jarIcon;
			else if (name.endsWith(".html") || name.endsWith("htm"))
				icon = htmlIcon;
			return icon;
		}
	}
}
